<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="../../css/mui.css"/>
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../../css/general.css"/>
		<style type="text/css">
			.main{
				width:100%;
				margin: 0.5em 0;
				background-color: white;
			}
			.flex1{
				display: flex;
				justify-content: center;
				align-items: center;
				padding: 0.5em;
			}
			.flex2{
				display: flex;
				justify-content: center;
				align-items: center;
				flex-direction: column;
				padding: 0.5em;
			}
			.flex1>div{
				width: 50%;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
			}
			.flex1>div>span{
				padding: 0.5em;
			}
			.ctext{
				position: absolute;
				top: 50%;
				right: 40px;
			    -webkit-transform: translateY(-50%);
			    transform: translateY(-50%);
			    padding: 0.3em;
			}
			.flex2>div{
				width: 100%;
			}
			.flex2>div>div{
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 0.2em;
				font-size: 0.9em;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav hbg">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left colorw"></a>
		    <h1 class="mui-title">积分</h1>
		</header>
		<div class="mui-content">
		    <div class="main flex1">
		    	<div class="border-r">
		    		<span id="">
		    			可用积分
		    		</span>
		    		<span id="stay_score">
		    			0
		    		</span>
		    	</div>
		    	<div class="">
		    		<span id="">
		    			累计积分
		    		</span>
		    		<span id="all_score">
		    			0
		    		</span>
		    	</div>
		    </div>
		    <div class="main">
		    	
		     	<ul class="mui-table-view">
		            <li class="mui-table-view-cell" id="add_score">
		                <a class="mui-navigate-right">
		                    	赠送积分
		                </a>
		               
		            </li>
		        </ul>    
		        
		    </div>
		    <div class="main">
		     	<ul class="mui-table-view">
		            <li class="mui-table-view-cell" id="reduce_score">
		                <a class="mui-navigate-right">
		                    	减少积分
		                </a>
		               
		            </li>
		        </ul>    
		    </div>
		  
           
		    <div class="main flex2 hidden" id="scorelist">
		    	
		    </div>
		   
		     
		     
		</div>
		<script src="../../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/req.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/muishow.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			
			var mid = 0,	//会员id
			page = 1;	//翻页
			window.onload = function(){
				mui.init();
				mid = getrequest().mid||0;
				
				//积分扣减
				g("reduce_score").addEventListener("tap",function(e){
					mui.prompt('请输入扣减的积分：', '', '', ["取消","确认"], function(e) {
	                    if (e.index == 1) {
	                       console.log(e.value);
	                       var data = {
	                       		url:"/api/member_score/reduce",
	                       		data:{
	                       			access_token:acctoken(),
	                       			member_id:mid,
	                       			score:e.value,
	                       		}
	                       }
	                       ajax(data,function(res){
	                       	console.log(res);
	                       	mui.toast(res.msg);
	                       	getmember();
	                       	getscore_list();
	                       })
	                       
	                       
	                    } else {
	                        
	                    }
	                })
					
				})
				
				//积分赠送
				g("add_score").addEventListener("tap",function(e){
					mui.prompt('请输入赠送的积分：', '', '', ["取消","确认"], function(e) {
	                    if (e.index == 1) {
	                       console.log(e.value);
	                       var data = {
	                       		url:"/api/member_score/add",
	                       		data:{
	                       			access_token:acctoken(),
	                       			member_id:mid,
	                       			score:e.value,
	                       		}
	                       }
	                       ajax(data,function(res){
	                       	console.log(res);
	                       	mui.toast(res.msg);
	                       	getmember();
	                       	getscore_list();
	                       })
	                       
	                       
	                    } else {
	                        
	                    }
	                })
					
				})
				
				getmember();
				getscore_list();
			}
			
			function getscore_list(){
				var data = {
					url:"/api/member_score/lst",
					data:{
						access_token:acctoken(),
						member_id:mid,
						page:page
					}
				}
				ajax(data,function(res){
					console.log("会员积分记录列表",res);
					
					setscore_list(res.data.data)
				})
			}
			
			function setscore_list(list){
				var str = '';
				if(list&&list.length >0){
					list.forEach(function(item,index){
					str += '<div class="border-b"><div class=""><span id="">'+
		    				item.score_name+
		    				'</span><span id="">';
		    				if(item.score_status == "支出"){
		    					str += '-'+item.score_count;
		    				}else if(item.score_status == "收入"){
		    					str += '+'+item.score_count;
		    				}else{
		    					str += item.score_count;
		    				}
		    				str += '</span></div>'+
		    				'<div class=""><span id="">'+
		    				item.createtime+
		    				'</span><span id="">'+
		    				item.record_status+
		    				'</span></div></div>';
					})
					g("scorelist").classList.remove("hidden");
					g("scorelist").innerHTML = str;
				}
				
			}
			
			function getmember(){
				var data = {
						url:"/api/member/detail",
						data:{
							access_token:acctoken(),
							id:mid,
						}
					}
					ajax(data,function(res){
						console.log("会员详情",res);
						//可用
						g("stay_score").innerHTML = res.data.stay_score;
						//使用
						//g("use_score").innerHTML = res.data.use_score;
						//累计
						g("all_score").innerHTML = res.data.all_score;
					})
			}
			
			
		</script>
	</body>

</html>